<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>控制台 - 教学管理系统首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <#include "../../head/common-js.ftl" />
    <#include "../../head/common-css.ftl" />
    <style>
        .label.label-xlg {
            margin-bottom: 5px
        }
    </style>
</head>
<body>
<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->
            <div class="row">
                <div class="col-sm-6" id="menu_info">
                    <div class="row">
                        <div class="col-sm-12">
                            <h3 class="header smaller lighter green">
                                <i class="icon-bookmark"></i>
                                用户详细信息
                            </h3>
                            <div class="profile-user-info profile-user-info-striped">
                                <div class="profile-info-row">
                                    <div class="profile-info-name">用户真实名称</div>
                                    <div class="profile-info-value">
                                    <span name="realName"
                                          id="realName">${user.realName}</span>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">用户登录名</div>
                                    <div class="profile-info-value">
                                    <span name="loginName"
                                          id="loginName">${user.loginName}</span>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">注册时间</div>
                                    <div class="profile-info-value">
                                        <span id="ceateTime">${user.createTime?string("yyyy-MM-dd HH:mm:ss")}</span>
                                    </div>
                                </div>
                                <div class="profile-info-row">
                                    <div class="profile-info-name">状态</div>
                                    <div class="profile-info-value">
                                        <span id="status">${(user.status == 1)?string("生效","失效")}</span>
                                    </div>
                                </div>
                                <div class="profile-info-row">
                                    <div class="profile-info-name">角色</div>
                                    <div class="profile-info-value">
                                <#if (user.userRoles?size > 0)>
                                    <div>
                                    <#list user.userRoles as userRole>
                                        <span class="label label-xlg label-success"
                                              onclick="showRoleDetail('${userRole.roleId}')">${userRole.roleName}</span>

                                    </#list>
                                    </div>
                                <#else>
                                    <span>没有角色</span>
                                </#if>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-12" hidden id="role_perms_div">
                            <div class="widget-box">
                                <div class="widget-header">
                                    <h5 class="smaller">权限信息</h5>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main padding-12">
                                        <div class="table-responsive page-content">
                                            <!-- table start -->
                                            <table class="table-list table-hover" id="role_perms_list"></table>
                                            <div class="pager" id="role_perms_page"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6" hidden id="role_menus_div">
                    <h3 class="header smaller lighter green">
                        <i class="icon-bookmark"></i>
                        角色菜单相关信息
                    </h3>
                    <div class="widget-box">
                        <div class="widget-header">
                            <h5 class="smaller">菜单信息</h5>
                        </div>

                        <div class="widget-body">
                            <div class="widget-main padding-6">
                                <div class="table-responsive page-content">
                                    <ul id="roleMenuTree" class="ztree">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
<script>
    // 属性菜单属性配置
    var setting = {
        view: {
            selectedMulti: false,
        },
        data: {
            simpleData: {
                enable: true,
                pIdKey: "pid"
            },
            key: {
                name: "menuName"
            }
        },
        callback: {
            onCollapse: function () {
                reinitTreeHight(window.parent.getIframeByElement(document.body));
            },
            onExpand: function () {
                reinitTreeHight(window.parent.getIframeByElement(document.body));
            }
        }
    };

    function showRoleDetail(roleId) {
        // 根据角色ID查询角色权限信息
        $('#role_perms_list').table({
            url: '${request.contextPath}/sys/role/doPermissionList.do',
            page: false,
            params: {
                'roleId': roleId
            },
            index: true,
            cont: 'role_perms_page',
            column: [{
                name: 'permissionCode',
                title: '权限编码',
                width: 80,
                align: 'center'
            }, {
                name: 'permissionName',
                title: '权限名称',
                width: 120,
                align: 'center',
            }]
        });
        // 获取菜单信息
        $.ajax({
            url: '${request.contextPath}/sys/role/doRoleMenuList.do',
            type: "post",
            dataType: "json",
            data: {
                'roleId': roleId
            },
            success: function (msg) {
                //要执行的代码
                if (!msg.success) {
                    layer.msg(msg.msg);
                    return;
                }
                //登录成功跳转页面
                var treeObj = $.fn.zTree.init($("#roleMenuTree"), setting, msg.results);
            }
        });
        $('#role_menus_div').show();
        $('#role_perms_div').show();
        setTimeout(function () {
            reinitTreeHight(window.parent.frames[0]);
        }, 200)
    }
</script>
</body>